package com.starblink.store.search.ui

import androidx.fragment.app.FragmentActivity
import com.starblink.android.basic.adapter.BaseBindingVH
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmPageDef
import com.starblink.rocketreserver.fragment.ProductF
import com.starblink.store.databinding.CellSimpleProductCardHorizontalBinding
import com.starblink.store.databinding.CellStoreSearchEmptyBinding
import com.starblink.store.databinding.CellStoreSearchRecommendTitleBinding
import com.starblink.store.search.bean.RvNoDataEntry
import com.starblink.store.search.bean.RvRecommendTitleEntry


/**
 * 列表项：搜索结果为空视图
 */
class SearchEmptyCell(
    binding: CellStoreSearchEmptyBinding,
) : BaseBindingVH<RvNoDataEntry, CellStoreSearchEmptyBinding>(binding = binding) {
    override fun onBind(model: RvNoDataEntry, position: Int) {
    }
}

/**
 * 列表项：推荐商品标题视图
 */
class RecommendTitleCell(
    binding: CellStoreSearchRecommendTitleBinding,
) : BaseBindingVH<RvRecommendTitleEntry, CellStoreSearchRecommendTitleBinding>(binding = binding) {

    override fun onBind(model: RvRecommendTitleEntry, position: Int) {
    }
}

/**
 * 列表项：横向商品卡片
 */
class ProductCardHorizontalCell(
    val activity: FragmentActivity,
    binding: CellSimpleProductCardHorizontalBinding,
    val searchProducts: ArrayList<Any>, // 搜索商品结果
    val searchKeyword: String, // 搜索关键字
) : BaseBindingVH<ProductF, CellSimpleProductCardHorizontalBinding>(binding) {

    override fun onBind(model: ProductF, position: Int) {
        // 埋点参数
        val searchResultEmpty: Boolean
        val trackPageForComparePriceDialog: Int
        var trackPosition = position
        if (searchProducts.isNotEmpty() && searchProducts.first() is RvRecommendTitleEntry) {
            // 店铺搜索空视图，推荐商品
            searchResultEmpty = true
            trackPageForComparePriceDialog = SpmPageDef.StoreSearchNoResultComparePriceDialog
            trackPosition -= 1 //position减去头部视图
            if (trackPosition < 0) {
                trackPosition = 0
            }
        } else {
            searchResultEmpty = false
            trackPageForComparePriceDialog = SpmPageDef.StoreSearchHasResultComparePriceDialog
        }
        binding.card.bindProduct(
            activity = activity,
            position = trackPosition,
            showTopBottomSpace = true,
            product = model,
            trackPage = SpmPageDef.StoreSearchResultPage,
            trackPageForComparePriceDialog = trackPageForComparePriceDialog,
            searchTerm = searchKeyword,
            searchResultEmpty = searchResultEmpty
        )
    }
}










